﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace MountainORocks
{
    class Shop
    {
        Rectangle dimondPlace = new Rectangle(127, 204, 80, 77);
        Rectangle rockPlace = new Rectangle(354, 211, 71, 69);
        Rectangle powerPlace = new Rectangle(545, 195, 95, 85);
        Vector2 textPlace = new Vector2(230, 325);
        Vector2 moneyPlace = new Vector2(50, 10);
        Game1 myGame;
        double timeBetweenBuy = 1.0;
        int dimondPrice = 500;
        int rockPrice = 75;
        int powerPrice = 150;
        MouseState currentMouse;
        Color noRockColor, powerColor, dimondColor;
        public Shop(Game1 thisGame)
        {
            myGame = thisGame;
        }

        public void update(GameTime gameTime)
        {

            currentMouse = Mouse.GetState();
            timeBetweenBuy -= gameTime.ElapsedGameTime.TotalSeconds;
            if ((timeBetweenBuy < 0) && (currentMouse.LeftButton == ButtonState.Pressed))
            {
                timeBetweenBuy = 0.4;
                if ((dimondPlace.Contains(currentMouse.X, currentMouse.Y)) && (myGame.playerMoney >= dimondPrice) && (myGame.levelCount > myGame.maxLevel))
                {
                    myGame.maxLevel++;
                    myGame.playerMoney -= dimondPrice;
                }

                if ((rockPlace.Contains(currentMouse.X, currentMouse.Y)) && (myGame.playerMoney >= rockPrice))
                {
                    myGame.rocksPower++;                  
                    myGame.playerMoney -= rockPrice;
                }

                if ((powerPlace.Contains(currentMouse.X, currentMouse.Y)) && (myGame.playerMoney >= powerPrice) && (myGame.bonusPower > 0.5))
                {
                    myGame.bonusPower -= 0.05;
                    myGame.rocksLevel++;
                    myGame.playerMoney -= powerPrice;

                }

            }
            Color tintColor = Color.Violet;
            tintColor.A = 30;
           
            if ((dimondPlace.Contains(currentMouse.X, currentMouse.Y)) && (myGame.playerMoney >= dimondPrice) && (myGame.levelCount > myGame.maxLevel))
            {
               dimondColor = tintColor;
            }
            else { dimondColor = Color.White; }
            if ((rockPlace.Contains(currentMouse.X, currentMouse.Y)) && (myGame.playerMoney >= rockPrice))
            {
                noRockColor = tintColor;
            }
            else { noRockColor = Color.White; }
            if ((powerPlace.Contains(currentMouse.X, currentMouse.Y)) && (myGame.playerMoney >= powerPrice) && (myGame.bonusPower > 0.5))
            {
              powerColor = tintColor; 
            }
            else { powerColor = Color.White; }



        }

        public void draw(SpriteBatch spriteBatch)
        {
          
            spriteBatch.Draw(myGame.shopTexture, new Rectangle(0, 0, myGame.WIDTH, myGame.HEIGHT), Color.White);
            spriteBatch.Draw(myGame.noRockTexture, rockPlace, noRockColor);
            spriteBatch.Draw(myGame.powerTexture, powerPlace, powerColor);
            spriteBatch.Draw(myGame.dimondTexture, dimondPlace, dimondColor);
            if (myGame.maxLevel < myGame.levelCount)
            {
                spriteBatch.DrawString(myGame.myFont, "max level: " + myGame.maxLevel, new Vector2(dimondPlace.X, dimondPlace.Y) - new Vector2(0, 29), Color.Black, 0.0f, Vector2.Zero, 0.35f, SpriteEffects.None, 0.5f);
            }
            else
            {
                spriteBatch.DrawString(myGame.myFont, "max level: maxed ", new Vector2(dimondPlace.X,dimondPlace.Y) - new Vector2(0, 29), Color.Black, 0.0f, Vector2.Zero, 0.35f, SpriteEffects.None, 0.5f);
            }
            spriteBatch.DrawString(myGame.myFont, "own: " + myGame.rocksPower, new Vector2(rockPlace.X, rockPlace.Y) - new Vector2(0, 36), Color.Black, 0.0f, Vector2.Zero, 0.35f, SpriteEffects.None, 0.5f);
            spriteBatch.DrawString(myGame.myFont, "level: " + myGame.rocksLevel, new Vector2(powerPlace.X, powerPlace.Y) - new Vector2(0, 20), Color.Black, 0.0f, Vector2.Zero, 0.35f, SpriteEffects.None, 0.5f);
            if (myGame.levelCount <= myGame.maxLevel)
            {
                spriteBatch.Draw(myGame.stockTexture, dimondPlace, Color.White * 0.8f);
            }

            if (myGame.bonusPower <= 0.5)
            {
                spriteBatch.Draw(myGame.stockTexture, powerPlace, Color.White * 0.8f);
            }

            if (dimondPlace.Contains(currentMouse.X, currentMouse.Y))
            {

                spriteBatch.DrawString(myGame.myFont, "get it to skip the current level", textPlace, Color.Black,0.0f,Vector2.Zero,0.65f,SpriteEffects.None,0.5f);
            }

            else if (powerPlace.Contains(currentMouse.X, currentMouse.Y))
            {

                spriteBatch.DrawString(myGame.myFont, "this will increase your \n disappearing power", textPlace, Color.Black, 0.0f, Vector2.Zero, 0.65f, SpriteEffects.None, 0.5f);
            }

            else if (rockPlace.Contains(currentMouse.X, currentMouse.Y))
            {

                spriteBatch.DrawString(myGame.myFont, "let you disappear one rock", textPlace, Color.Black, 0.0f, Vector2.Zero, 0.65f, SpriteEffects.None, 0.5f);
            }

            else
                spriteBatch.DrawString(myGame.myFont, "press Esc to leave shop", textPlace, Color.Black, 0.0f, Vector2.Zero, 0.65f, SpriteEffects.None, 0.5f);

            spriteBatch.DrawString(myGame.myFont, "money: " + myGame.playerMoney.ToString(), moneyPlace, Color.Black, 0.0f, Vector2.Zero, 0.65f, SpriteEffects.None, 0.5f);
           
        }



    }
}
